﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TYBase;

namespace KPI.Entity
{
    public class RPage<T> : R<T>
    {

        public RPage<T> SetDataCount(int dataCount)
        {
            if (this.page != null)
                this.page.DataCount = dataCount;

            return this;
        }
        public new List<T> data { get; set; }

        public RPage(PageInfo pageInfo)
        {
            if (pageInfo != null)
            {
                page = new PageInfo(pageInfo.PageIndex, pageInfo.PageSize);
            }
            else
            {
                page = new PageInfo(1, 30);
            }
        }

        public static new RPage<T> Fail(string message, int code = 1)
        {
            RPage<T> rPage = new RPage<T>(null);
            rPage.code = code;
            rPage.msg = message;
            return rPage;
        }
        public static new RPage<T> Fail(string v, Exception ex)
        {
            RPage<T> rPage = new RPage<T>(null);
            rPage.data = default;
            rPage.code = 1;
            rPage.msg = $"{v},{ex.Info()}";
            return rPage;
        }
        public static RPage<T> OK(List<T> t, PageInfo page)
        {
            RPage<T> rPage = new RPage<T>(page);
            rPage.data = t;
            rPage.code = 0;
            return rPage;
        }


        public int GetDataCount()
        {
            return page.DataCount;
        }


        public static new RPage<T> Fail(int code)
        {
            RPage<T> rPage = new RPage<T>(null);
            rPage.code = code;
            return rPage;
        }
        public PageInfo page;
    }



}
